<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            选择点位
        </div>
    </header>
    <script id="opTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setQualchkitem('{{= it[index].sysid }}','{{= it[index].code }}','{{= it[index].name }}');">   
            <div class="aui-list-item-inner">

                <div>{{= it[index].code }}:{{= it[index].name }}</div>
                <input type='checkbox' name='checkboxName' value='{{= it[index].code }}:{{= it[index].name }}'>
            </div>
        </li>
        {{~}}

    </script>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="请输入气密数字" id="name">
                    </form>
                </div>
                <!-- <i class="aui-iconfont aui-icon-roundclosefill" tapmode onclick="clearInput()"></i> -->
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4" onclick="doSearch()">搜索</div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4" onclick="goPage()">带回</div>
        </div>
        <ul class="aui-list aui-list-in" id="opList">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>

<script type="text/javascript">
    var workCenterCode
    var content
    var arrSaveId = []
    var arrSaveName = []
            // 创建一个空数组来存储选中复选框的值

    apiready = function() {
        workCenterCode = api.pageParam.workCenterCode;
        doSearch();
    };

    //查询物料列表
    function doSearch() {
        var name = $("#name").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/usmSelectPoint";
        var data = {
            values: {
                un: un,
                workCenterCode:workCenterCode,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var mydata = eval(myobj.list);
                    var evaluation = doT.template($api.dom('#opTemp').innerHTML);
                    $api.dom('#opList').innerHTML = evaluation(mydata);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选则返回函数
    function setQualchkitem(sysid, code, name) {
        // 获取所有名为"checkboxName"的复选框
        var checkboxes = document.querySelectorAll('input[name="checkboxName"]:checked');
        var valuesName = [];
        // 遍历选中的复选框，并将其值添加到数组中
        checkboxes.forEach(function(checkbox) {
            valuesName.push(checkbox.value);
        });
       
        if(content){
            arrSaveName = content+','+valuesName
        }else{
            arrSaveName = valuesName
        }
    }
    function goPage(){
        console.log(arrSaveName)

        api.closeWin();
        var nameR = api.pageParam.name;
        api.execScript({
            name: nameR,
            script: 'setQualchkitem("' + arrSaveName + '")'
        });
    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
